#ifndef FTBITMAPCHAR_H_
#define FTBITMAPCHAR_H_

#include <GlobalData.h>
#include <ft2build.h>
#include <freetype.h>

struct FT_GlyphRec_;
class GLCallBatcher;

const int verticesPerQuad = 4;
const int indicesPerQuad = 6;
const int compVertPos = 2;
const int compVertTex = 2;

// each FTBitmapChar represents a character from the fnt file
// reads paramaters from fnt file and creates textured quad   
class FTBitmapChar
{
//private:
public:
	int 			x, y;
	int 			width;
	int 			height;
	int 			xOffset;
	int 			yOffset;
	int 			xAdvance;
	int 			charCode;	// for debugging
	float 			texCoords[verticesPerQuad*compVertTex];
	FT_GlyphRec_	*glyph;
    
public:
	FTBitmapChar();
	FTBitmapChar(int charCode)	{ this->charCode = charCode; }
	~FTBitmapChar();
    
	void    releaseGlyph();
	void    initTexCoords(int texWidth, int texHeight);
	void    drawToBitmap(unsigned char* data, int texWidth, int texHeight);
	void    addKerning(FTBitmapChar* bitmapChar, int amount);

	void    render(int x, int y, float scale, GLCallBatcher *glCallBatcher) const;
	void    setXY(int x, int y)                     { this->x = x; this->y = y; }
	void    setXAdvance(int xAdvance)               { this->xAdvance = xAdvance; }
	void    setSize(int width, int height)          { this->width = width; this->height = height; }
	void    setOffsets(int xOffset, int yOffset)    { this->xOffset = xOffset; this->yOffset = yOffset; }
	void    setCharCode(int charCode)               { this->charCode = charCode; }
	void    setGlyph(struct FT_GlyphRec_* glyph)    { this->glyph = glyph; }
	int     getX2() const                           { return x + width; }
	int     getY2() const                           { return x + width; }
	int     getXAdvance() const                     { return xAdvance; }
	int     getHeight() const                       { return height; }
	int     getTotalHeight() const                  { return yOffset + height; }
	int     getWidth() const                        { return width; }
	int     getYOffset() const                      { return yOffset; }
	int     getNumPixels() const                    { return width*height; }
	int     getCharCode() const                     { return charCode; }
	bool    isEmpty() const                         { return width == 0 || height == 0; }
	bool    isLoaded() const                        { return x >= 0; }
	void    reduceYOffset(int amount)               { yOffset -= amount; }};

#endif /*FTBITMAPCHAR_H_*/
